package InetTest;

import org.junit.Test;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

/**
 * @author 李泽伟
 */
public class MainTest {
    @Test
    public void test() {
        try {
            //写法1: 具体IP地址
            InetAddress name = InetAddress.getByName("127.0.0.1");
            System.out.println(name);
            //写法2：www.baidu.com域名地址，网络DNS域名解析器
            InetAddress name2 = InetAddress.getByName("www.vip.com");
            System.out.println(name2);
            InetAddress host = InetAddress.getLocalHost();
            //DESKTOP-3OLRI0N / 10.180.60.71(局域网里)
            System.out.println(host);
            System.out.println(host.getHostAddress());
            System.out.println(host.getHostName());
            System.out.println(Arrays.toString(host.getAddress()));
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
    }
}
